package com.sc.common.response;

import lombok.Data;
import lombok.Getter;

@Getter
public class Response<T> {
    public static final int SUCCESS = 200;
    public static final int FAIL = 202;
    public static final int ERROR = 500;

    private final int code;

    private final String message;

    private final T data;

    private Response() {
        this.code = SUCCESS;
        this.message = "success";
        this.data = null;
    }

    private Response(int code, String msg, T data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    public static <T> Response<T> success() {
        return new Response<>();
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(SUCCESS, "success", data);
    }

    public static <T> Response<T> success(T data, String msg) {
        return new Response<>(SUCCESS, msg, data);
    }

    public static <T> Response<T> fail(String msg) {
        return new Response<>(FAIL, msg, null);
    }

    public static <T> Response<T> fail(String msg, T data) {
        return new Response<>(FAIL, msg, data);
    }

    public static <T> Response<T> fail(String msg, int code) {
        return new Response<>(code, msg, null);
    }

    public static <T> Response<T> error(String msg) {
        return new Response<>(ERROR, msg, null);
    }

    public static <T> Response<T> create(int code, String msg, T data) {
        return new Response<>(ERROR, msg, data);
    }

}
